package com.qzsoft.zhjd.asphalt.modules.common.controller;

import java.util.List;
import java.util.Map;

import com.qzsoft.zhjd.asphalt.modules.common.service.AsphaltCommonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.qzsoft.jeemis.common.utils.Result;
import com.qzsoft.zhjd.asphalt.modules.asphaltdata.entity.AsphaltDataEntity;
import com.qzsoft.zhjd.common.utils.ResultUtils;

/**
 * @ClassName AsphaltCommonController
 * @Description 沥青通用控制器
 * @author linhuawei
 * @since 2022-04-21
 */
@RestController
@RequestMapping("/api/asphaltCommon")
public class AsphaltCommonController {

    @Autowired
    private AsphaltCommonService asphaltCommonService;

    /**
     * @Title getLastData
     * @Description 获取最新一条数据
     * @param params 查询条件
     * @return 最新一条数据
     */
    @GetMapping("/getLastData")
    public Result<AsphaltDataEntity> getLastData(@RequestParam Map<String, Object> params){
        AsphaltDataEntity data = asphaltCommonService.getLastData(params);
        return ResultUtils.ok(data);
    }

    /**
     * @Title getLastDay
     * @Description 获取最新数据日期
     * @param params 查询条件
     * @return 最新数据日期
     */
    @GetMapping("/getLastDay")
    public Result<String> getLastDay(@RequestParam Map<String, Object> params) {
        String data = asphaltCommonService.getLastDay(params);
        return ResultUtils.ok(data);
    }

    /**
     * @Title getLastMonth
     * @Description 获取最新数据月份
     * @param params 查询条件
     * @return 最新数据月份
     */
    @GetMapping("/getLastMonth")
    public Result<String> getLastMonth(@RequestParam Map<String, Object> params) {
        String data = asphaltCommonService.getLastMonth(params);
        return ResultUtils.ok(data);
    }

    /**
     * @Title getLastYear
     * @Description 获取最新数据年份
     * @param params 查询条件
     * @return 最新数据年份
     */
    @GetMapping("/getLastYear")
    public Result<String> getLastYear(@RequestParam Map<String, Object> params) {
        String data = asphaltCommonService.getLastYear(params);
        return ResultUtils.ok(data);
    }


    /**
     * @Title getAllYear
     * @Description 获取所有有生产数据的年份
     * @param params 查询条件
     * @return 所有有生产数据的年份
     */
    @GetMapping("/getAllYear")
    public Result<List<String>> getAllYear(@RequestParam Map<String, Object> params) {
        List<String> data = asphaltCommonService.getAllYear(params);
        return ResultUtils.ok(data);
    }

}
